package com.zhixiang.xaec.action.safebase.safecultruetrain;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.entity.TreeObj;
import com.zhixiang.core.util.String2Array;
import com.zhixiang.core.util.YearGridCrud;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.safebase.safecultruetrain.CultureActivity;
import com.zhixiang.xaec.service.safebase.safecultruetrain.CultureActivityService;

@Controller
@Scope("prototype")
public class CultureActivityAction extends  BaseAction{
	/**
	 * 
	 */
	 private static final long serialVersionUID = 1L;

	 private CultureActivity cultureActivity;
	 
	 @Autowired
	 private CultureActivityService cultureActivityService ;
	
	 public CultureActivity getCultureActivity() {
		return cultureActivity;
	}
	
	 public void setCultureActivity(CultureActivity cultureActivity) {
		this.cultureActivity = cultureActivity;
	}
	 
	   public String save()
	    {
		   try{
			   
		   
		    cultureActivityService.save(cultureActivity);
	       
		   }catch(Exception e){
			   
		   }
		   return SUCCESS;
	    }

	    public String delete()
	    {
	        try
	        {
	            String [] ids = getRequest().getParameterValues("ids");
	         
	            cultureActivityService.delete(ids);
	        }
	        catch (Exception e)
	        {
	            setSuccess(false);
	            setMsg("删除失败");
	        }

	        return SUCCESS;
	    }

	    public String get()
	    {
	    	String id=getRequest().getParameter("id");
	        if (StringUtils.isNotEmpty(id))
	        {
	            setResult(cultureActivityService.get(Long.valueOf(id)));
	        }
	        return SUCCESS;
	    }
	    
	    public String list()
	    {
	        QueryFilter localQueryFilter = new QueryFilter(getRequest());
	        List<CultureActivity> localList =cultureActivityService.getAll(localQueryFilter);
	        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
	        setResult(localList);
	        return SUCCESS;
	    } 
	    
	    //实现年份数的方法
	    public String treeLoad(){
	        List<TreeObj> treeList=YearGridCrud.treeLoad();
	        if(treeList!=null){
	            outJsonString(new Gson().toJson(treeList));
	        }       
	        return SUCCESS;
	    }
}
